package com.itheima.mapper;

import com.itheima.domain.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @program: sharding_sphere
 * @description: 这个是Order的mapper层
 * @author: zhanghz001
 * @create: 2021-03-18 09:06
 **/
@Mapper
public interface OrderMapper {
    //新增
    @Insert("insert into t_order(price,user_id,status) values(#{price},#{userId},#{status})")
    public int inserOrder(Order order);
    
    //根据id查询多个订单
    @Select({"<script>" +
            " select *\n" +
            "from t_order t\n" +
            "where t.order_id in " +
            "<foreach collection='orderIds' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>"})
    public List<Map> selectListByOrderIds(@Param("orderIds") List<Long> orderIds);
    
    //根据id查询多个订单,其中含有分表(order_id),分库(user_id)
    @Select({"<script>" +
            " select *\n" +
            "from t_order t\n" +
            "where t.order_id in " +
            "<foreach collection='orderIds' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>\n" +
            " and user_id=#{userId}" +
            "</script>"})
    public List<Map> selectListByUserIdAndOrderIds(@Param("userId") long userId, @Param("orderIds") List<Long> orderIds);
}
